#include<stdio.h> 
//#include<conio.h> 
#define null 0 
void create(); 
void display(); 
void insert(); 
void delet(); 
void erase(); 
void create2(); 
void display2(); 
void insert2(); 
void delet2(); 
void erase2(); 
void link1(); 
void link2(); 
void merge(); 
struct node 
{ 
int info; 
struct node *next; 
}*start,*ptr,*temp,*prev; 
struct node2 
{ 
int info; 
struct node2 *nex; 
}*start2,*ptr2,*temp2,*prev2; 
void main() 
{ 
int op; 
//clrscr(); 
do 
{ 
printf("\n1.link1\n2.link2\n3.merge\n4.exit"); 
printf("\nEnter your option"); 
scanf("%d",&op); 
switch(op) 
{ 
case 1: 
link1(); 
break; 
case 2: 
link2(); 
break; 
case 3: 
merge(); 
break; 
case 4: 
break; 
default: 
printf("\nEnter correct option"); 
} 
}while(op!=4); 
//getch(); 
} 
void create() 
{ 
int data; 
printf("\nEnter the data"); 
scanf("%d",&data); 
do 
{ 
ptr=malloc(sizeof(struct node)); 
ptr->info=data; 
ptr->next=NULL; 
if(start==NULL) 
start=ptr; 
else 
{ 
temp=start; 
while(temp->next!=NULL) 
{ 
temp=temp->next; 
} 
temp->next=ptr; 
} 
printf("\nEnter the data & Press 0 to terminate"); 
scanf("%d",&data); 
}while(data!=0); 
} 
void display() 
{ 
temp=start; 
if(start==NULL) 
printf("\nList is empty"); 
else 
{ 
printf("\nElements of list:\n"); 
while(temp->next!=NULL) 
{ 
printf("%d\t",temp->info); 
temp=temp->next; 
} 
printf("%d\t",temp->info); 
} 
} 
void insert() 
{ 
int data,pos; 
printf("\nEnter data & position to insert the element"); 
scanf("d",&data,&pos); 
temp=start; 
ptr=malloc(sizeof(struct node)); 
ptr->info=data; 
while(temp->next!=NULL) 
{ 
if(temp->info==pos) 
{ 
ptr->next=temp->next; 
temp->next=ptr; 
break; 
} 
else 
temp=temp->next; 
} 
if(temp->next==NULL) 
{ 
temp->next=ptr; 
ptr->next=NULL; 
} 
} 
void delet() 
{ 
int pos,flag=0; 
if(start==NULL) 
printf("List is empty"); 
else 
{ 
printf("Enter element to be deleted"); 
scanf("%d",&pos); 
temp=start; 
if(start->info==pos) 
{ 
flag=1; 
start=start->next; 
free(temp); 
} 
else 
{ 
while(temp->next!=NULL) 
{ 
prev=temp; 
temp=temp->next; 
if(temp->info==pos) 
{ 
flag=1; 
prev->next=temp->next; 
free(temp); 
break; 
} 
} 
} 
if(flag==0) 
printf("\nElement is not present in list"); 
} 
} 
void erase() 
{ 
if(start==NULL) 
printf("\nList is empty"); 
else 
{ 
while(start->next!=NULL) 
{ 
temp=start; 
start=start->next; 
free(temp); 
} 
temp=start; 
start=start->next; 
free(temp); 
printf("list is erased"); 
} 
} 
void create2() 
{ 
int data; 
printf("\nEnter the data"); 
scanf("%d",&data); 
do 
{ 
ptr2=malloc(sizeof(struct node2)); 
ptr2->info=data; 
ptr2->nex=NULL; 
if(start2==NULL) 
start2=ptr2; 
else 
{ 
temp2=start2; 
while(temp2->nex!=NULL) 
{ 
temp2=temp2->nex; 
} 
temp2->nex=ptr2; 
} 
printf("\nEnter the data & Press 0 to terminate"); 
scanf("%d",&data); 
}while(data!=0); 
} 
void display2() 
{ 
temp2=start2; 
if(start2==NULL) 
printf("\nList is empty"); 
else 
{ 
printf("\nElements of list:\n"); 
while(temp2->nex!=NULL) 
{ 
printf("%d\t",temp2->info); 
temp2=temp2->nex; 
} 
printf("%d\t",temp2->info); 
} 
} 
void insert2() 
{ 
int data,pos; 
printf("\nEnter data & position to insert the element"); 
scanf("d",&data,&pos); 
temp2=start2; 
ptr2=malloc(sizeof(struct node2)); 
ptr2->info=data; 
while(temp2->nex!=NULL) 
{ 
if(temp2->info==pos) 
{ 
ptr2->nex=temp2->nex; 
temp2->nex=ptr2; 
break; 
} 
else 
temp2=temp2->nex; 
} 
if(temp2->nex==NULL) 
{ 
temp2->nex=ptr2; 
ptr2->nex=NULL; 
} 
} 
void delet2() 
{ 
int pos,flag=0; 
if(start2==NULL) 
printf("List is empty"); 
else 
{ 
printf("Enter element to be deleted"); 
scanf("%d",&pos); 
temp2=start2; 
if(start2->info==pos) 
{ 
flag=1; 
start2=start2->nex; 
free(temp2); 
} 
else 
{ 
while(temp2->nex!=NULL) 
{ 
prev2=temp2; 
temp2=temp2->nex; 
if(temp2->info==pos) 
{ 
flag=1; 
prev2->nex=temp2->nex; 
free(temp2); 
break; 
} 
} 
} 
if(flag==0) 
printf("\nElement is not present in list"); 
} 
} 
void erase2() 
{ 
if(start2==NULL) 
printf("\nList is empty"); 
else 
{ 
while(start2->nex!=NULL) 
{ 
temp2=start2; 
start2=start2->nex; 
free(temp2); 
} 
temp2=start2; 
start2=start2->nex; 
free(temp2); 
printf("list is erased"); 
} 
} 
void link1() 
{ 
int op; 
start=NULL; 
do 
{ 
printf("\n1.create\n2.display\n3.insert\n4.delete\n5.erase\n6.exit"); 
printf("\nEnter your option"); 
scanf("%d",&op); 
switch(op) 
{ 
case 1: 
create(); 
break; 
case 2: 
display(); 
break; 
case 3: 
insert(); 
break; 
case 4: 
delet(); 
break; 
case 5: 
erase(); 
break; 
case 6: 
break; 
default: 
printf("\nEnter correct option"); 
} 
}while(op!=6); 
//getch(); 
} 
void link2() 
{ 
int op; 
start2=NULL; 
do 
{ 
printf("\n1.create\n2.display\n3.insert\n4.delete\n5.erase\n6.exit"); 
printf("\nEnter your option"); 
scanf("%d",&op); 
switch(op) 
{ 
case 1: 
create2(); 
break; 
case 2: 
display2(); 
break; 
case 3: 
insert2(); 
break; 
case 4: 
delet2(); 
break; 
case 5: 
erase2(); 
break; 
case 6: 
break; 
default: 
printf("\nEnter correct option"); 
} 
}while(op!=6); 
//getch(); 
} 
void merge() 
{ 
if(start==NULL) 
{ 
start=start2; 
} 
else 
{ 
temp=start; 
while(temp->next!=NULL) 
{ 
temp=temp->next; 
} 
temp->next=start2; 
} 
temp=start; 
if(start==NULL) 
printf("\nList is empty"); 
else 
{ 
printf("\nElements of list:\n"); 
while(temp!=NULL) 
{ 
printf("%d\t",temp->info); 
temp=temp->next; 
} 
} 
//getch(); 
}
